FROM arm64v8/maven:3.8.6-openjdk-8-slim

COPY sources.list    /etc/apt/sources.list
RUN apt-get update && apt-get install unzip && apt-get clean all

ARG user=rocketmq
ARG group=rocketmq
ARG uid=3000
ARG gid=3000

# RocketMQ Dashboard runs with user `rocketmq`, uid = 3000
# If you bind mount a volume from the host or a data container,
# ensure you use the same uid
   
RUN  groupadd -g ${gid} ${group} \
    && useradd -u ${uid} -g ${gid} -m -s /bin/bash ${user}



ENV ROCKETMQ_DASHBOARD_VERSION 1.0.0
ENV ROCKETMQ_DASHBOARD_HOME  /home/rocketmq

WORKDIR ${ROCKETMQ_DASHBOARD_HOME}

ADD rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}-source-release.zip ${ROCKETMQ_DASHBOARD_HOME}/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}-source-release.zip

RUN  unzip rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}-source-release.zip ; \
     mv rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION} rocketmq-dashboard ; 
    
COPY application.properties users.properties   ${ROCKETMQ_DASHBOARD_HOME}/rocketmq-dashboard/src/main/resources/
RUN sed -i '159i \
    <mirror> \
       <id>alimaven</id> \
       <name>aliyun maven</name> \
       <url>http://maven.aliyun.com/nexus/content/groups/public/</url> \
       <mirrorOf>central</mirrorOf> \
     </mirror> \
' ${MAVEN_HOME}/conf/settings.xml

RUN cd rocketmq-dashboard ; \
    mvn -DskipTests clean install ;\
    ls -l target ; 


RUN mkdir bin; \
    mv rocketmq-dashboard/target/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}.jar bin/ ; \
    mv bin/rocketmq-dashboard-${ROCKETMQ_DASHBOARD_VERSION}.jar bin/rocketmq-dashboard.jar; \
    ls -l bin; 
    
RUN rm -rf ${MAVEN_CONFIG}/repository/*
RUN rm -rf ${MAVEN_HOME}
RUN chown -R ${uid}:${gid} ${ROCKETMQ_DASHBOARD_HOME}/rocketmq-dashboard 
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "bin/rocketmq-dashboard.jar"]